﻿<div class="page-bar">
    <ul class="page-breadcrumb">
        <li>
            <span id="module">系统管理员</span>
            <i class="fa fa-angle-right"></i>
        </li>
        <li>
            <span id="action"></span>
        </li>
    </ul>
</div>
<!-- END PAGE BAR -->
<div class="mt-bootstrap-tables" style="margin-top:20px">
    <div class="row">
        <div class="col-md-12">
            <div class="portlet light bordered">
                <div class="portlet-title">
                    <div class="caption">
                        <i class="icon-social-dribbble font-green hide"></i>
                    </div>
                    <div class="actions">
                        <a href="javascript:void(0)" class="btn btn-default btnAdd">
                            <i class="fa fa-plus"></i> 快速添加
                        </a>
                        @*<a href="@Url.Action("Edit")" class="btn btn-default">
                            <i class="fa fa-plus"></i> 添加
                        </a>*@
                    </div>
                </div>

                <div class="portlet-body">
                    <!-- BEGIN FORM-->
                    <form id="defaultForm" class="form-horizontal" method="post" novalidate="novalidate">
                        @*<div class="mt-checkbox-inline" style="margin-top: -37px">
                                <div class="pull-left" style="margin-top: 20px">
                                    状态：
                                    <select class="form-control input-inline" name="Deleted" id="State">
                                        <option value="">全部</option>
                                        <option value="1">正常</option>
                                        <option value="0">禁用</option>
                                    </select>
                                </div>
                            </div>*@
                    </form>
                    <!-- END FORM-->
                    <table id="table-pagination" data-toggle="table" data-url="@Url.Action("GetPagedList")"
                           data-height="526"
                           data-form-id="defaultForm"
                           data-show-refresh="true"
                           data-page-size="10"
                           data-page-list="[5, 10, 20, 50, 100, 200]"
                           data-auto-height="true"
                           data-search="true">
                        <thead>
                            <tr>
                                <th data-formatter="RowNumber" data-width="50">序号</th>
                                <th data-field="Account">姓名</th>
                                <th data-align="center" data-field="CreatedTime" data-width="160">创建时间</th>
                                <th data-align="center" data-formatter="opColumns" data-width="150">操作</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>

            <!-- 参数设置 弹出框模板 -->
            <div id="dialogTemplet" class="hide">
                <form class="form-horizontal" method="post">
                    <div class="form-body">
                        <div class="row">
                            <div class="col-md-10">
                                <div class="form-group">
                                    <label class="control-label col-md-2">账号</label>
                                    <div class="col-md-10">
                                        <input type="hidden" name="Id" class="form-control" value="" />
                                        <input type="text" name="Account" class="form-control" value="" required />
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-10">
                                <div class="form-group">
                                    <label class="control-label col-md-2">密码</label>
                                    <div class="col-md-10">
                                        <input type="password" name="Password" class="form-control" value="" required />
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <!-- End 弹出框模板 -->
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        var opColumns = function (value, row, index) {
            var dataModel = escape(JSON.stringify(row));
            
            var html = `<a href="javascript:edit('_id_')">重置密码</a> `;//| <a href="javascript:remove('_id_')" >删除</a>

            return html.replace(/_id_/ig, row.Id);
        },
        remove = function (id) {
            bootbox.confirm("是否确认删除？", function (result) {
                if (!result) {
                    return;
                }
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("Delete")',
                    data: { id: id },
                    async: false,
                    success: function (result) {
                        if (result.Success) {
                            $('#table-pagination').bootstrapTable('refresh');
                        } else {
                            showToast(3, '系统消息', result.Message);
                        }
                    }
                });
            });
        },
        showDialog = function (parameter) {
            var settingParamDialog = bootbox.dialog({
                title: '编辑管理员',
                message: $('#dialogTemplet').html(),
                className: 'my-modal',
                buttons: {
                    success: {
                        label: '取 消'
                    },
                    main: {
                        label: '确 定',
                        callback: function () {
                            var formDoc = $('.my-modal .modal-body form');
                            formDoc.submit();
                            return false;
                        }
                    }
                }
            });
            //初始化弹出框
            settingParamDialog.init(function () {
                var formDoc = $('.my-modal .modal-body form');

                if (parameter.Account != undefined) {
                    $("input[name='Id']", formDoc).val(parameter.Id);
                    $("input[name='Account']", formDoc).val(parameter.Account);
                    //$("input[name='Password']", formDoc).val(dataModel.Password);
                }

                customFormValidate(formDoc, {
                    Account: {
                        required: true,
                        remote: {
                            url: "@Url.Action("ValidateAccount")",
                            type: "post",
                            dataType: "json",
                            data: {
                                Id: function () {
                                    return $("input[name='Id']", formDoc).val();　　　　//这个是取要验证的密码
                                },
                                Account: function () {
                                    return $("input[name='Account']", formDoc).val();　　　　//这个是取要验证的密码
                                }
                            },
                            dataFilter: function (data) {　　　　//判断控制器返回的内容
                                if (eval(data)) {
                                    return true;
                                }
                                else {
                                    return false;
                                }
                            }
                        }
                    }
                }, function (form) {
                    var data = $(form).serializeObject();
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Action("Save")',
                        data: data,
                        async: false,
                        success: function (reslut) {
                            if (reslut.Success) {
                                bootbox.hideAll(); //关闭弹出框
                                showToast(0, '系统提示', '保存成功');
                                $('#table-pagination').bootstrapTable('refresh');
                            } else {
                                showToast(3, '系统提示', reslut.Message);
                            }
                        },
                        error: function (request) {
                            showToast(3, '系统提示', ' 操作失败!');
                        }
                    });

                });
            });
        };

        $('.btnAdd').click(showDialog);

        function edit(id) {
            
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("GetById")',
                    data: { id: id },
                    async: false,
                    success: function (result) {
                        showDialog(result);
                    }
                });
        }

    </script>
}
